<?php defined('IN_ADMIN') or exit('Access Denied!'); ?>
<?php
    @list($wtime1, $wtime2) = explode('-', $data['worktime']);
    $data['worktime'] = array($wtime1, $wtime2);
    @list($dtime1, $dtime2, $dtime3, $dtime4) = preg_split('/[\s-]+/', $data['delivery_time']);
    $data['delivery_time'] = array($dtime1, $dtime2, $dtime3, $dtime4);
?>
<div class="subnav">
  <div class="content-menu ib-a blue line-x">
    <a><em>外卖信息</em></a> <span>|</span>
    <a class="on"><em>编辑外卖</em></a>
  </div>
</div>
<form action="/admin/waimai/save/<?=isset($data['shop_id'])?intval($data['shop_id']):'';?>" method="post" id="myform">
  <input type="hidden" name="method" value="<?=$method;?>" />
  <div class="pad-10">
    <div class="col-tab">
      <ul class="tabBut cu-li" id="tab_setting">
        <li id="tab_setting_1" class="on">送餐信息</li>
        <li id="tab_setting_2" class="off">
            <a href="#" onclick="show_dialog('deliver', '/admin/waimai/deliver/<?=$data['shop_id'];?>', '设置配送区域');">设置配送区域</a></li>
      </ul>
      <div id="div_setting_1" class="contentList pad-10">
        <table width="100%"  class="table_form">
          <tr>
            <th width="120">最低消费</th>
            <td class="y-bg"><input type="text" class="input-text" name="min_charge" id="min_charge" size="40" value="<?=h($data['min_charge']);?>"/></td>
          </tr>
          <tr>
            <th width="120">起送份数</th>
            <td class="y-bg"><input type="text" class="input-text" name="min_order" id="min_order" size="40" value="<?=h($data['min_order']);?>"/></td>
          </tr>
          <tr>
            <th width="120">送餐时间</th>
            <td class="y-bg">
            <select name="delivery_time[0]" id="delivery_time_0">
            <option value="" selected>请选择...</option>
            <?php echo shop_time_option(6, 20, $data['delivery_time'][0]);?>
            </select>
            ~
            <select name="delivery_time[1]" id="delivery_time_1">
            <option value="" selected>请选择...</option>
            <?php echo shop_time_option(10, 24, $data['delivery_time'][1]);?>
            </select>
            <br />
            <select name="delivery_time[2]" id="delivery_time_2">
            <option value="" selected>请选择...</option>
            <?php echo shop_time_option(13, 20, $data['delivery_time'][2]);?>
            </select>
            ~
            <select name="delivery_time[3]" id="delivery_time_3">
            <option value="" selected>请选择...</option>
            <?php echo shop_time_option(14, 24, $data['delivery_time'][3]);?>
            </select>
           </td>
          </tr>
          <tr>
            <th width="120">配送描述</th>
            <td class="y-bg"><textarea name="delivery_desc" cols="47" rows="3" id="delivery_desc"><?=h($data['delivery_desc']);?></textarea>
              &nbsp;&nbsp;&nbsp;&nbsp;<font color="gray">送餐区域，送餐时间，是否有送餐费等信息。</font></td>
          </tr>
          <tr>
            <th width="120">&nbsp;</th>
            <td class="y-bg"><a href="#" onclick="show_dialog('deliver', '/admin/waimai/deliver/<?=$data['shop_id'];?>', '设置配送区域');"><u>单击这里设置详细配送区域</u></a></td>
          </tr>
        </table>
      </div>
      <div class="bk15"></div>
      <input name="dosubmit" type="submit" value="提交" class="button">
    </div>
  </div>
</form>
<script type="text/javascript">
$(document).ready(function(){
    //tabs('#tab_setting', 'setting');

    $.formValidator.initConfig({formid:"myform",autotip:true,onerror:function(msg,obj){window.top.art.dialog({content:msg,lock:true,width:'200',height:'50'}, function(){this.close();$(obj).focus();})}});
    $("#name").formValidator({onshow:"请输入外卖名称",onfocus:"请输入外卖名称"}).inputValidator({min:1,onerror:"外卖名称没有填写"});
    $("#zone_id,#subzone_id").formValidator({onshow:"请选择区域/板块",onfocus:"请选择区域/板"}).functionValidator({
        fun:function(){
            return ($("#subzone_id").val() >0 && $("#zone_id").val() > 0);
        },
        onerror:"区域/板块没有选择"
    });
    $("#address").formValidator({onshow:"请输入外卖地址",onfocus:"请输入外卖地址"}).inputValidator({min:1,onerror:"外卖地址没有填写"});
    $("#topic").formValidator({onshow:"请输入外卖简介",onfocus:"请用一句话描述，100字以内"}).inputValidator({max:100,onerror:"简介内容至多100字"});
})

</script>

<?php
    function shop_time_option($from, $to, $time){
        $time = isset($time) ? $time : '';
        for($i=$from*2;$i<=$to*2;$i++){
            $tmp = date("H:i", $i*1800 + 3600*16);
            $sel = ($time == $tmp) ? ' selected' : '';
            echo '<option value="' .$tmp. '"' .$sel. '>' .$tmp. '</option>';
        }
    }
?>